/*     */ package com.chw.admin.contractHeader;
/*     */ import java.util.Date;
/*     */ import java.util.List;

/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Service;

/*     */ 
/*     */ import com.chw.admin.contractLine.ChwContractLine;
/*     */ import com.chw.admin.contractLine.ChwContractLineMapper;
/*     */ import com.chw.utils.CommonFieldsUtil;
/*     */ import com.chw.utils.UUIDUtil;
/*     */ import com.github.pagehelper.PageHelper;
/*     */ import com.github.pagehelper.PageInfo;
/*     */   
/*     */ @Service
/*     */ public class ChwHeaderService
/*     */   implements IChwHeaderService 
/*     */ {
/*     */ 
/*     */   @Autowired
/*     */   private ChwContractHeaderMapper chwContractHeaderMapper;
/*     */ 
/*     */   @Autowired
/*     */   private ChwContractLineMapper chwContractLineMapper;
/*     */ 
/*     */   public PageInfo<ChwContractHeader> find(ChwContractHeader chwContractHeader, Integer currentPage, Integer pageSize)
/*     */   {
/*  26 */     PageHelper.startPage(currentPage.intValue(), pageSize.intValue());
/*  27 */     List list = this.chwContractHeaderMapper.findByChwContractHeader(chwContractHeader);
/*  28 */     return new PageInfo(list);
/*     */   }
/*     */
/*     */   public PageInfo<ChwContractLine> findChwLine(ChwContractLine chwContractLine, Integer currentPage, Integer pageSize)
/*     */   {
/*  26 */     PageHelper.startPage(currentPage.intValue(), pageSize.intValue());
/*  27 */     List<ChwContractLine> list = this.chwContractLineMapper.findByEntity(chwContractLine);
/*  28 */     return new PageInfo(list);
/*     */   }
/*     */ 
/*     */   public int addHeaderLine(ChwContractHeader chwContractHeader, List<ChwContractLine> list)
/*     */   {
/*     */     try {
/*  34 */       chwContractHeader.setContractHeaderId(UUIDUtil.getUUID());
/*  35 */       CommonFieldsUtil.setCreateValueByCy(chwContractHeader);
/*  36 */       this.chwContractHeaderMapper.insert(chwContractHeader);
/*  37 */       if (list.size() > 0) {
/*  38 */         for (int i = 0; i < list.size(); i++) {
/*  39 */           ChwContractLine chwContractLine = (ChwContractLine)list.get(i);
/*  40 */           CommonFieldsUtil.setCreateValueByCy(chwContractLine);
/*  41 */           chwContractLine.setContractHeaderId(chwContractHeader.getContractHeaderId());
/*  42 */           chwContractLine.setContractLineId(UUIDUtil.getUUID());
/*  43 */           this.chwContractLineMapper.insert(chwContractLine);
/*     */         }
/*     */       }
/*  46 */       return 0;
/*     */     } catch (Exception e) {
/*  48 */       e.printStackTrace();
/*     */     }
/*  50 */     return 1;
/*     */   }
/*     */ 
/*     */   public int updateHeaderLine(ChwContractHeader chwContractHeader, List<ChwContractLine> list)
/*     */   {
/*     */     try
/*     */     {
/*  57 */       chwContractHeader.setLastUpdatedDate(new Date());
/*  58 */       chwContractHeader.setEnabledFlag("Y");
/*  59 */       this.chwContractHeaderMapper.updateByPrimaryKey(chwContractHeader);
/*  60 */       if (list.size() > 0)
/*     */       {
/*  62 */         ChwContrachHeaderLine chwContrachHeaderLine = getHeaderLineById(chwContractHeader.getContractHeaderId());
/*  63 */         List lines = chwContrachHeaderLine.getChwContractLine();
/*  64 */         if (lines!=null && lines.size() > 0) {
/*  65 */           for (int j = 0; j < lines.size(); j++) {
/*  66 */             ChwContractLine cj = (ChwContractLine)lines.get(j);
/*  67 */             cj.setEnabledFlag("N");
/*  68 */             this.chwContractLineMapper.updateByPrimaryKey(cj);
/*     */           }
/*     */         }
/*  71 */         for (int i = 0; i < list.size(); i++) {
/*  72 */           ChwContractLine chwContractLine = (ChwContractLine)list.get(i);
/*  73 */           if ("".equals(chwContractLine.getContractLineId())) {
/*  74 */             CommonFieldsUtil.setCreateValueByCy(chwContractLine);
/*  75 */             chwContractLine.setContractLineId(UUIDUtil.getUUID());
/*  76 */             chwContractLine.setContractHeaderId(chwContractHeader.getContractHeaderId());
/*  77 */             this.chwContractLineMapper.insert(chwContractLine);
/*     */           } else {
/*  79 */             chwContractLine.setContractHeaderId(chwContractHeader.getContractHeaderId());
/*  80 */             chwContractLine.setLastUpdatedDate(new Date());
/*  81 */             chwContractLine.setEnabledFlag("Y");
					  chwContractLine.setContractLineId(chwContractLine.getContractLineId());
/*  82 */             this.chwContractLineMapper.updateByPrimaryKey(chwContractLine);
/*     */           }
/*     */         }
/*     */       }
/*  86 */       return 0;
/*     */     } catch (Exception e) {
/*  88 */       e.printStackTrace();
/*     */     }
/*  90 */     return 1;
/*     */   }
/*     */ 
/*     */   public int delHeader(String id)
/*     */   {
/*     */     try
/*     */     {
/*  97 */       ChwContractHeader chwContrachHeader = this.chwContractHeaderMapper.selectByPrimaryKey(id);
/*  98 */       chwContrachHeader.setEnabledFlag("N");
/*  99 */       this.chwContractHeaderMapper.updateByPrimaryKey(chwContrachHeader);
/* 100 */       return 0;
/*     */     } catch (Exception e) { 
/* 102 */       e.printStackTrace();
/*     */     }
/* 104 */     return 1;
/*     */   }
/*     */ 
/*     */   public ChwContrachHeaderLine getHeaderLineById(String id)
/*     */   {
/* 109 */     ChwContractHeader chwContrachHeader = this.chwContractHeaderMapper.selectByPrimaryKey(id);
/* 110 */     ChwContrachHeaderLine chwContrachHeaderLine = new ChwContrachHeaderLine();
/* 111 */     chwContrachHeaderLine.setChwContractHeader(chwContrachHeader);
/* 112 */     List list = this.chwContractLineMapper.findByChwContractHeaderId(id);
/* 113 */     if (list.size() > 0) {
/* 114 */       chwContrachHeaderLine.setChwContractLine(list);
/*     */     }
/* 116 */     return chwContrachHeaderLine;
/*     */   }
/*     */ }

/* Location:           E:\chenya\haha\admin java\contractHeader\
 * Qualified Name:     com.chw.admin.contractHeader.ChwHeaderService
 * JD-Core Version:    0.6.0
 */